﻿namespace LeetCodeProject._0001_1000._001_100._81_90._082;

public class Solution
{
    public ListNode DeleteDuplicates(ListNode head)
    {
        if (head == null)
            return null;
        var dummy = new ListNode(0) { next = head };
        var pre = dummy;
        var cur = pre.next;
        while (cur != null)
        {
            if (cur.next != null && cur.val == cur.next.val)
            {
                var node = cur.next.next;
                while (node != null && cur.val == node.val)
                    node = node.next;
                pre.next = cur = node;
            }
            else
            {
                pre = cur;
                cur = cur.next;
            }
        }

        return dummy.next;
    }
}